package org.jeecg.modules.online.cgform.controller;

import cn.hutool.core.io.FileUtil;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.google.common.collect.Lists;
import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.UnsupportedEncodingException;
import java.lang.invoke.SerializedLambda;
import java.net.URLDecoder;
import java.net.URLEncoder;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.sql.DataSource;
import org.apache.commons.io.IOUtils;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.aspect.annotation.AutoLog;
import org.jeecg.common.aspect.annotation.OnlineAuth;
import org.jeecg.common.constant.enums.ModuleType;
import org.jeecg.common.exception.TuringBootException;
import org.jeecg.common.system.api.ISysBaseAPI;
import org.jeecg.common.system.util.JwtUtil;
import org.jeecg.common.system.vo.DictModel;
import org.jeecg.common.system.vo.LoginUser;
import org.jeecg.common.util.BrowserUtils;
import org.jeecg.common.util.RedisUtil;
import org.jeecg.common.util.SpringContextUtils;
import org.jeecg.common.util.SqlInjectionUtil;
import org.jeecg.common.util.TokenUtils;
import org.jeecg.common.util.oConvertUtils;
import org.jeecg.config.JeecgBaseConfig;
import org.jeecg.modules.online.auth.p004b.AuthConstants;
import org.jeecg.modules.online.auth.service.IOnlAuthPageService;
import org.jeecg.modules.online.cgform.consts.OnlineConst;
import org.jeecg.modules.online.cgform.converter.ConvertUtil;
import org.jeecg.modules.online.cgform.entity.OnlCgformField;
import org.jeecg.modules.online.cgform.entity.OnlCgformHead;
import org.jeecg.modules.online.cgform.enums.CgformConstant;
import org.jeecg.modules.online.cgform.model.OnlCgformModel;
import org.jeecg.modules.online.cgform.model.OnlComplexModel;
import org.jeecg.modules.online.cgform.model.OnlGenerateModel;
import org.jeecg.modules.online.cgform.model.TreeModel;
import org.jeecg.modules.online.cgform.p007a.LinkDown;
import org.jeecg.modules.online.cgform.service.IOnlCgformAiService;
import org.jeecg.modules.online.cgform.service.IOnlCgformFieldService;
import org.jeecg.modules.online.cgform.service.IOnlCgformHeadService;
import org.jeecg.modules.online.cgform.service.IOnlCgformSqlService;
import org.jeecg.modules.online.cgform.service.IOnlineJoinQueryService;
import org.jeecg.modules.online.cgform.service.IOnlineService;
import org.jeecg.modules.online.cgform.utils.CgFormExcelHandler;
import org.jeecg.modules.online.cgform.utils.CgformUtil;
import org.jeecg.modules.online.cgform.utils.GenerateCodeFileToZip;
import org.jeecg.modules.online.cgform.utils.OnlineImportValidator;
import org.jeecg.modules.online.cgreport.constant.CgReportConstant;
import org.jeecg.modules.online.config.exception.BusinessException;
import org.jeecg.modules.online.config.exception.DBException;
import org.jeecg.modules.online.config.p022d.DbTableUtil;
import org.jeecgframework.codegenerate.database.DbReadTableUtil;
import org.jeecgframework.poi.excel.ExcelExportUtil;
import org.jeecgframework.poi.excel.ExcelImportUtil;
import org.jeecgframework.poi.excel.entity.ExportParams;
import org.jeecgframework.poi.excel.entity.ImportParams;
import org.jeecgframework.poi.excel.entity.enmus.ExcelType;
import org.jeecgframework.poi.excel.entity.params.ExcelExportEntity;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.context.annotation.Lazy;
import org.springframework.jdbc.support.incrementer.OracleSequenceMaxValueIncrementer;
import org.springframework.jdbc.support.incrementer.PostgreSQLSequenceMaxValueIncrementer;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartHttpServletRequest;

@RequestMapping({"/online/cgform/api"})
@RestController("onlCgformApiController")
/* renamed from: org.jeecg.modules.online.cgform.c.a */
/* loaded from: hibernate-re-3.7.1-RC.jar:org/jeecg/modules/online/cgform/c/a.class */
public class OnlCgformApiController {

    /* renamed from: a */
    private static final Logger f144a = LoggerFactory.getLogger(OnlCgformApiController.class);
    @Autowired
    private IOnlCgformHeadService onlCgformHeadService;
    @Autowired
    IOnlineJoinQueryService onlineJoinQueryService;
    @Autowired
    private IOnlCgformFieldService onlCgformFieldService;
    @Autowired
    private IOnlCgformSqlService onlCgformSqlService;
    @Autowired
    private IOnlAuthPageService onlAuthPageService;
    @Autowired
    @Lazy
    private ISysBaseAPI sysBaseAPI;
    @Autowired
    private IOnlineService onlineService;
    @Value("${jeecg.path.upload}")
    private String upLoadPath;
    @Value("${jeecg.uploadType}")
    private String uploadType;
    @Autowired
    private RedisUtil redisUtil;
    @Autowired
    private JeecgBaseConfig jeecgBaseConfig;
    @Autowired
    private IOnlCgformAiService iOnlCgformAiService;


    @PostMapping({"/addAll"})
    /* renamed from: a */
    public Result<?> m487a(@RequestBody OnlCgformModel onlCgformModel) {
        try {
            String tableName = onlCgformModel.getHead().getTableName();
            if (DbTableUtil.m38a(tableName).booleanValue()) {
                return Result.error("数据库表[" + tableName + "]已存在,请从数据库导入表单");
            }
            if (onlCgformModel.getHead().getTableType().intValue() == 3) {
                if (oConvertUtils.isEmpty(onlCgformModel.getHead().getRelationType())) {
                    return Result.error("附表必须选择映射关系！");
                }
                if (oConvertUtils.isEmpty(onlCgformModel.getHead().getTabOrderNum())) {
                    return Result.error("附表必须填写排序序号！");
                }
            }
            return this.onlCgformHeadService.addAll(onlCgformModel);
        } catch (Exception e) {
            f144a.error("OnlCgformApiController.addAll()发生异常：" + e.getMessage(), e);
            return Result.error("操作失败");
        }
    }

   
    /* renamed from: a */
    /**
     * 通过AI生成一个模块的表设计
     * @param onlCgformModel
     * @return
     */
    @PostMapping({"/aigc"})
    public Result<?> m501a(@RequestParam(name = "prompt", required = true) String str) {
        return this.iOnlCgformAiService.genSchema4Modules(str);
    }

    @PutMapping({"/editAll"})
    @CacheEvict(value = {"sys:cache:online:list", "sys:cache:online:form"}, allEntries = true, beforeInvocation = true)
    /* renamed from: b */
    public Result<?> m480b(@RequestBody OnlCgformModel onlCgformModel) {
        try {
            if (onlCgformModel.getHead().getTableType().intValue() == 3) {
                if (oConvertUtils.isEmpty(onlCgformModel.getHead().getRelationType())) {
                    return Result.error("附表必须选择映射关系！");
                }
                if (oConvertUtils.isEmpty(onlCgformModel.getHead().getTabOrderNum())) {
                    return Result.error("附表必须填写排序序号！");
                }
            }
            return this.onlCgformHeadService.editAll(onlCgformModel);
        } catch (Exception e) {
            f144a.error("OnlCgformApiController.editAll()发生异常：" + e.getMessage(), e);
            return Result.error("操作失败");
        }
    }

    @OnlineAuth("getColumns")
    @AutoLog(operateType = 1, value = "online列表加载", module = ModuleType.ONLINE)
    @GetMapping({"/getColumns/{code}"})
    /* renamed from: a */
    public Result<OnlComplexModel> m495a(@PathVariable("code") String str, HttpServletRequest httpServletRequest) {
        Result<OnlComplexModel> result = new Result<>();
        try {
            OnlCgformHead table = this.onlCgformHeadService.getTable(str);
            String parameter = httpServletRequest.getParameter(OnlineConst.f139a);
            if (oConvertUtils.isNotEmpty(parameter)) {
                table.setSelectFieldString(parameter);
            }
            LoginUser loginUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
            OnlComplexModel queryOnlineConfig = this.onlineService.queryOnlineConfig(table, loginUser.getUsername());
            queryOnlineConfig.setIsDesForm(table.getIsDesForm());
            queryOnlineConfig.setDesFormCode(table.getDesFormCode());
            result.setResult(queryOnlineConfig);
            result.setOnlTable(table.getTableName());
            return result;
        } catch (DBException e) {
            result.error500("Online表单不存在！");
            return result;
        }
    }

    @OnlineAuth("getData")
    @GetMapping({"/getData/{code}"})
    /* renamed from: b */
    public Result<Map<String, Object>> m482b(@PathVariable("code") String str, HttpServletRequest httpServletRequest) {
        Map<String, Object> queryAutolistPage;
        Result<Map<String, Object>> result = new Result<>();
        try {
            OnlCgformHead table = this.onlCgformHeadService.getTable(str);
            if (oConvertUtils.isEmpty(table.getPhysicId()) && "N".equals(table.getIsDbSynch())) {
                result.error500("NO_DB_SYNC");
                return result;
            }
            String parameter = httpServletRequest.getParameter(OnlineConst.f139a);
            if (oConvertUtils.isNotEmpty(parameter)) {
                table.setSelectFieldString(parameter);
            }
            try {
                Map<String, Object> m358a = CgformUtil.m358a(httpServletRequest);
                if (CgformUtil.m349a(table)) {
                    queryAutolistPage = this.onlineJoinQueryService.pageList(table, m358a);
                } else {
                    queryAutolistPage = this.onlCgformFieldService.queryAutolistPage(table, m358a, null);
                }
                m489a(table, queryAutolistPage);
                result.setResult(queryAutolistPage);
            } catch (Exception e) {
                f144a.error(e.getMessage(), e);
                result.error500("数据库查询失败，" + e.getMessage());
            }
            result.setOnlTable(table.getTableName());
            return result;
        } catch (DBException e2) {
            result.error500("实体不存在");
            return result;
        }
    }

    @OnlineAuth("getFormItem")
    @AutoLog(operateType = 1, value = "online表单加载", module = ModuleType.ONLINE)
    @GetMapping({"/getFormItem/{code}"})
    /* renamed from: c */
    public Result<?> m476c(@PathVariable("code") String str, HttpServletRequest httpServletRequest) {
        try {
            OnlCgformHead table = this.onlCgformHeadService.getTable(str);
            Result result = new Result<>();
            LoginUser loginUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
            String parameter = httpServletRequest.getParameter("selectFields");
            if (oConvertUtils.isNotEmpty(parameter)) {
                Arrays.asList(parameter.split(CgformUtil.f233E));
            }
            result.setResult(CgformUtil.m345b(this.onlineService.queryOnlineFormItem(table, loginUser.getUsername())));
            result.setOnlTable(table.getTableName());
            return result;
        } catch (DBException e) {
            return Result.error("Online表单不存在！");
        }
    }

    @AutoLog(operateType = 1, value = "online根据表名加载表单", module = ModuleType.ONLINE)
    @GetMapping({"/getFormItemBytbname/{table}"})
    /* renamed from: a */
    public Result<?> m497a(@PathVariable("table") String str, @RequestParam(name = "taskId", required = false) String str2) {
        Result result = new Result<>();
        LambdaQueryWrapper<OnlCgformHead> lambdaQueryWrapper = new LambdaQueryWrapper();
        lambdaQueryWrapper.eq(OnlCgformHead::getTableName, str);
        OnlCgformHead onlCgformHead = (OnlCgformHead) this.onlCgformHeadService.getOne(lambdaQueryWrapper);
        if (onlCgformHead == null) {
            Result.error("Online表单不存在！");
        }
        result.setResult(CgformUtil.m345b(this.onlineService.queryFlowOnlineFormItem(onlCgformHead, ((LoginUser) SecurityUtils.getSubject().getPrincipal()).getUsername(), str2)));
        result.setOnlTable(str);
        return result;
    }

    @OnlineAuth("getEnhanceJs")
    @GetMapping({"/getEnhanceJs/{code}"})
    /* renamed from: d */
    public Result<?> m472d(@PathVariable("code") String str, HttpServletRequest httpServletRequest) {
        return Result.ok(this.onlineService.queryEnahcneJsString(str, CgformUtil.f271aq));
    }

    @AutoLog(operateType = 1, value = "online表单数据查询")
    @GetMapping({"/form/{code}/{id}"})
    /* renamed from: b */
    public Result<?> m483b(@PathVariable("code") String str, @PathVariable("id") String str2) {
        try {
            SqlInjectionUtil.filterContent(str2, CgformUtil.f231C);
            return Result.ok(CgformUtil.m361a(this.onlCgformHeadService.queryManyFormData(str, str2)));
        } catch (Exception e) {
            f144a.error("Online表单查询异常：" + e.getMessage(), e);
            return Result.error("查询失败，" + e.getMessage());
        }
    }

    @AutoLog(operateType = 1, value = "online表单数据查询")
    @GetMapping({"/detail/{code}/{id}"})
    /* renamed from: c */
    public Result<?> m477c(@PathVariable("code") String str, @PathVariable("id") String str2) {
        try {
            SqlInjectionUtil.filterContent(str2, CgformUtil.f231C);
            Map<String, Object> queryManyFormData = this.onlCgformHeadService.queryManyFormData(str, str2);
            ArrayList arrayList = new ArrayList();
            arrayList.add(CgformUtil.m361a(queryManyFormData));
            this.onlCgformFieldService.handleLinkTableDictData(this.onlCgformHeadService.getTable(str).getId(), arrayList);
            return Result.ok(arrayList.get(0));
        } catch (Exception e) {
            f144a.error("Online表单查询异常：" + e.getMessage(), e);
            return Result.error("查询失败，" + e.getMessage());
        }
    }

    @GetMapping({"/subform/{table}/{mainId}"})
    /* renamed from: d */
    public Result<?> m473d(@PathVariable("table") String str, @PathVariable("mainId") String str2) {
        try {
            SqlInjectionUtil.filterContent(str2, CgformUtil.f231C);
            return Result.ok(CgformUtil.m361a(this.onlCgformHeadService.querySubFormData(str, str2)));
        } catch (Exception e) {
            f144a.error("Online表单查询异常：" + e.getMessage(), e);
            return Result.error("查询失败，" + e.getMessage());
        }
    }

    @GetMapping({"/subform/list/{table}/{mainId}"})
    /* renamed from: e */
    public Result<?> m470e(@PathVariable("table") String str, @PathVariable("mainId") String str2) {
        try {
            SqlInjectionUtil.filterContent(str2, CgformUtil.f231C);
            return Result.ok(this.onlCgformHeadService.queryManySubFormData(str, str2));
        } catch (Exception e) {
            f144a.error("Online表单查询异常：" + e.getMessage(), e);
            return Result.error("查询失败，" + e.getMessage());
        }
    }

    @AutoLog(operateType = 1, value = "online根据表名查询表单数据", module = ModuleType.ONLINE)
    @GetMapping({"/form/table_name/{tableName}/{dataId}"})
    /* renamed from: f */
    public Result<?> m468f(@PathVariable("tableName") String str, @PathVariable("dataId") String str2) {
        try {
        	LambdaQueryWrapper<OnlCgformHead> lambdaQueryWrapper = new LambdaQueryWrapper();
            lambdaQueryWrapper.eq(OnlCgformHead::getTableName, str);
            OnlCgformHead onlCgformHead = this.onlCgformHeadService.getOne(lambdaQueryWrapper);
            if (onlCgformHead == null) {
                throw new Exception("OnlCgform tableName: " + str + " 不存在！");
            }
            SqlInjectionUtil.filterContent(str2, CgformUtil.f231C);
            Result<?> m483b = m483b(onlCgformHead.getId(), str2);
            m483b.setOnlTable(str);
            return m483b;
        } catch (Exception e) {
            f144a.error("Online表单查询异常，" + e.getMessage(), e);
            return Result.error("查询失败，" + e.getMessage());
        }
    }

    @OnlineAuth(CgformUtil.f271aq)
    @PostMapping({"/form/{code}"})
    @AutoLog(operateType = 2, value = "online新增数据", module = ModuleType.ONLINE)
    @CacheEvict(value = {OnlineConst.f141c}, allEntries = true)
    /* renamed from: a */
    public Result<String> m499a(@PathVariable("code") String str, @RequestBody JSONObject jSONObject, HttpServletRequest httpServletRequest) {
        Result<String> result = new Result<>();
        try {
            String m385a = CgformUtil.m385a();
            jSONObject.put("id", m385a);
            String saveManyFormData = this.onlCgformHeadService.saveManyFormData(str, jSONObject, TokenUtils.getTokenByRequest(httpServletRequest));
            result.setSuccess(true);
            result.setResult(m385a);
            result.setOnlTable(saveManyFormData);
            result.setMessage("添加成功!");
        } catch (Exception e) {
            f144a.error("OnlCgformApiController.formAdd()发生异常：", e);
            result.setSuccess(false);
            result.setMessage("保存失败，" + CgformUtil.m382a(e));
        }
        return result;
    }

    @OnlineAuth(CgformUtil.f271aq)
    @AutoLog(operateType = 3, value = "online修改数据", module = ModuleType.ONLINE)
    @PutMapping({"/form/{code}"})
    @CacheEvict(value = {OnlineConst.f141c}, allEntries = true)
    /* renamed from: a */
    public Result<?> m500a(@PathVariable("code") String str, @RequestBody JSONObject jSONObject) {
        try {
            String editManyFormData = this.onlCgformHeadService.editManyFormData(str, jSONObject);
            Result<?> ok = Result.ok("修改成功！");
            ok.setOnlTable(editManyFormData);
            return ok;
        } catch (Exception e) {
            f144a.error("OnlCgformApiController.formEdit()发生异常：" + e.getMessage(), e);
            return Result.error("修改失败，" + CgformUtil.m382a(e));
        }
    }

    @OnlineAuth(CgformUtil.f271aq)
    @DeleteMapping({"/form/{code}/{id}"})
    @AutoLog(operateType = AuthConstants.f111o, value = "online删除数据", module = ModuleType.ONLINE)
    /* renamed from: g */
    public Result<?> m466g(@PathVariable("code") String str, @PathVariable("id") String str2) {
        OnlCgformHead onlCgformHead = (OnlCgformHead) this.onlCgformHeadService.getById(str);
        if (onlCgformHead == null) {
            return Result.error("实体不存在");
        }
        try {
            String str3 = "";
            if ("Y".equals(onlCgformHead.getIsTree())) {
                str2 = this.onlCgformFieldService.queryTreeChildIds(onlCgformHead, str2);
                str3 = this.onlCgformFieldService.queryTreePids(onlCgformHead, str2);
            }
            if (str2.indexOf(CgformUtil.f233E) > 0) {
                if (onlCgformHead.getTableType().intValue() == 2) {
                    this.onlCgformFieldService.deleteAutoListMainAndSub(onlCgformHead, str2);
                } else {
                    this.onlCgformFieldService.deleteAutoListById(onlCgformHead.getTableName(), str2);
                }
                if ("Y".equals(onlCgformHead.getIsTree())) {
                    String tableName = onlCgformHead.getTableName();
                    String treeIdField = onlCgformHead.getTreeIdField();
                    for (String str4 : str3.split(CgformUtil.f233E)) {
                        this.onlCgformFieldService.updateTreeNodeNoChild(tableName, treeIdField, str4);
                    }
                }
            } else {
                this.onlCgformHeadService.deleteOneTableInfo(str, str2);
            }
            if (oConvertUtils.isNotEmpty(onlCgformHead.getIsDesForm())) {
                if ("1".equals(onlCgformHead.getIsDesForm())) {
                }
            }
            Result<?> ok = Result.ok("删除成功!");
            ok.setOnlTable(onlCgformHead.getTableName());
            return ok;
        } catch (Exception e) {
            f144a.error("OnlCgformApiController.formEdit()发生异常：" + e.getMessage(), e);
            return Result.error("删除失败," + e.getMessage());
        }
    }

    @DeleteMapping({"/formByCode/{code}/{id}"})
    @AutoLog(operateType = AuthConstants.f111o, value = "online删除数据", module = ModuleType.ONLINE)
    /* renamed from: h */
    public Result<?> m465h(@PathVariable("code") String str, @PathVariable("id") String str2) {
        try {
            String deleteDataByCode = this.onlCgformHeadService.deleteDataByCode(str, str2);
            Result<?> OK = Result.OK("删除成功!", deleteDataByCode);
            OK.setOnlTable(deleteDataByCode);
            return OK;
        } catch (TuringBootException e) {
            return Result.error(e.getMessage());
        }
    }

    @OnlineAuth("getQueryInfo")
    @GetMapping({"/getQueryInfo/{code}"})
    /* renamed from: b */
    public Result<?> m485b(@PathVariable("code") String str) {
        try {
            return Result.ok(this.onlCgformFieldService.getAutoListQueryInfo(str));
        } catch (Exception e) {
            f144a.error("OnlCgformApiController.getQueryInfo()发生异常：" + e.getMessage(), e);
            return Result.error("查询失败");
        }
    }

    @GetMapping({"/getQueryInfoVue3/{code}"})
    /* renamed from: c */
    public Result<?> m479c(@PathVariable("code") String str) {
        try {
            return Result.ok(this.onlineService.getOnlineVue3QueryInfo(str));
        } catch (Exception e) {
            f144a.error("获取online查询配置异常：" + e.getMessage(), e);
            return Result.error("获取Online表单的查询条件失败!");
        }
    }

    @PostMapping({"/doDbSynch/{code}/{synMethod}"})
    @RequiresPermissions({"online:form:syncDb"})
    /* renamed from: i */
    public Result<?> m464i(@PathVariable("code") String str, @PathVariable("synMethod") String str2) {
        try {
            System.currentTimeMillis();
            this.onlCgformHeadService.doDbSynch(str, str2);
            return Result.ok("同步数据库成功!");
        } catch (Exception e) {
            f144a.error(e.getMessage(), e);
            return Result.error("同步数据库失败，" + CgformUtil.m382a(e));
        }
    }

    /* JADX WARN: Multi-variable type inference failed */
    /* JADX WARN: Type inference failed for: r0v47, types: [java.util.Map] */
    @OnlineAuth("exportXls")
    @GetMapping({"/exportXls/{code}"})
    /* renamed from: a */
    public void m494a(@PathVariable("code") String str, HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) {
        OnlCgformHead onlCgformHead = (OnlCgformHead) this.onlCgformHeadService.getById(str);
        if (onlCgformHead == null) {
            return;
        }
        onlCgformHead.getTableTxt();
        String parameter = httpServletRequest.getParameter("paramsStr");
        Map hashMap = new HashMap(5);
        if (oConvertUtils.isNotEmpty(parameter)) {
            hashMap = JSONObject.parseObject(parameter, Map.class);
        }
        XSSFWorkbook handleOnlineExport = this.onlineJoinQueryService.handleOnlineExport(onlCgformHead, hashMap);
        OutputStream outputStream = null;
        try {
            try {
                httpServletResponse.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
                String str2 = onlCgformHead.getTableTxt() + "-v" + onlCgformHead.getTableVersion();
                if ("MSIE".equalsIgnoreCase(BrowserUtils.checkBrowse(httpServletRequest).substring(0, 4))) {
                    httpServletResponse.setHeader("content-disposition", "attachment;filename=" + URLEncoder.encode(str2, "UTF-8") + ".xlsx");
                } else {
                    httpServletResponse.setHeader("content-disposition", "attachment;filename=" + new String(str2.getBytes("UTF-8"), "ISO8859-1") + ".xlsx");
                }
                outputStream = httpServletResponse.getOutputStream();
                handleOnlineExport.write(outputStream);
                httpServletResponse.flushBuffer();
                if (outputStream != null) {
                    try {
                        outputStream.close();
                    } catch (IOException e) {
                        f144a.error(e.getMessage(), e);
                    }
                }
            } catch (Exception e2) {
                f144a.error("--通过流的方式获取文件异常--" + e2.getMessage(), e2);
                if (outputStream != null) {
                    try {
                        outputStream.close();
                    } catch (IOException e3) {
                        f144a.error(e3.getMessage(), e3);
                    }
                }
            }
        } catch (Throwable th) {
            if (outputStream != null) {
                try {
                    outputStream.close();
                } catch (IOException e4) {
                    f144a.error(e4.getMessage(), e4);
                }
            }
            throw th;
        }
    }

    /* JADX WARN: Multi-variable type inference failed */
    /* JADX WARN: Type inference failed for: r0v111, types: [java.util.List] */
    /* JADX WARN: Type inference failed for: r0v118, types: [java.util.Map] */
    @OnlineAuth("exportXlsOld")
    @GetMapping({"/exportXlsOld/{code}"})
    /* renamed from: b */
    public void m481b(@PathVariable("code") String str, HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) {
        OnlCgformHead onlCgformHead = (OnlCgformHead) this.onlCgformHeadService.getById(str);
        if (onlCgformHead == null) {
            return;
        }
        String tableTxt = onlCgformHead.getTableTxt();
        String parameter = httpServletRequest.getParameter("paramsStr");
        Map hashMap = new HashMap(5);
        if (oConvertUtils.isNotEmpty(parameter)) {
            hashMap =  JSONObject.parseObject(parameter, Map.class);
        }
        hashMap.put("pageSize", -521);
        Map<String, Object> pageList = CgformUtil.m349a(onlCgformHead) ? this.onlineJoinQueryService.pageList(onlCgformHead, hashMap, true) : this.onlCgformFieldService.queryAutolistPage(onlCgformHead, hashMap, null);
        List list = (List) pageList.get("fieldList");
        List<Map<String, Object>> list2 = (List<Map<String, Object>>)pageList.get("records");
        List arrayList = new ArrayList();
        String obj = hashMap.get("selections") == null ? null : hashMap.get("selections").toString();
        if (oConvertUtils.isNotEmpty(obj)) {
            List<String> m312h = CgformUtil.m312h(obj);
            arrayList = list2.stream().filter(map -> {
                return m312h.contains(map.get("id"));
            }).collect(Collectors.toList());
        } else {
            arrayList.addAll(list2 == null?new ArrayList():list2);
        }
        ConvertUtil.m398a(1, arrayList, list);
        try {
            this.onlCgformHeadService.executeEnhanceExport(onlCgformHead, arrayList);
        } catch (BusinessException e) {
            f144a.error("导出java增强处理出错", e.getMessage());
        }
        List<ExcelExportEntity> m337b = CgformUtil.m337b(list, "id", this.upLoadPath);
        if (onlCgformHead.getTableType().intValue() == 2 && oConvertUtils.isEmpty(hashMap.get(CgformUtil.f277aw))) {
            String subTableStr = onlCgformHead.getSubTableStr();
            if (oConvertUtils.isNotEmpty(subTableStr)) {
                for (String str2 : subTableStr.split(CgformUtil.f233E)) {
                    this.onlineJoinQueryService.addAllSubTableDate(str2, hashMap, arrayList, m337b, false);
                }
            }
        }
        ExportParams exportParams = new ExportParams((String) null, oConvertUtils.getNormalString(tableTxt));
        exportParams.setType(ExcelType.XSSF);
        Workbook exportExcel = ExcelExportUtil.exportExcel(exportParams, m337b, arrayList);
        OutputStream outputStream = null;
        try {
            try {
                httpServletResponse.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
                String checkBrowse = BrowserUtils.checkBrowse(httpServletRequest);
                String normalString = oConvertUtils.getNormalString(onlCgformHead.getTableTxt() + "-v" + onlCgformHead.getTableVersion());
                if ("MSIE".equalsIgnoreCase(checkBrowse.substring(0, 4))) {
                    httpServletResponse.setHeader("content-disposition", "attachment;filename=" + URLEncoder.encode(normalString, "UTF-8") + ".xlsx");
                } else {
                    httpServletResponse.setHeader("content-disposition", "attachment;filename=" + new String(normalString.getBytes("UTF-8"), "ISO8859-1") + ".xlsx");
                }
                outputStream = httpServletResponse.getOutputStream();
                exportExcel.write(outputStream);
                httpServletResponse.flushBuffer();
                if (outputStream != null) {
                    try {
                        outputStream.close();
                    } catch (IOException e2) {
                        f144a.error(e2.getMessage(), e2);
                    }
                }
            } catch (Exception e3) {
                f144a.error("--通过流的方式获取文件异常--" + e3.getMessage(), e3);
                if (outputStream != null) {
                    try {
                        outputStream.close();
                    } catch (IOException e4) {
                        f144a.error(e4.getMessage(), e4);
                    }
                }
            }
        } catch (Throwable th) {
            if (outputStream != null) {
                try {
                    outputStream.close();
                } catch (IOException e5) {
                    f144a.error(e5.getMessage(), e5);
                }
            }
            throw th;
        }
    }

    @OnlineAuth("importXls")
    @PostMapping({"/importXls/{code}"})
    /* renamed from: c */
    public Result<?> m475c(@PathVariable("code") String str, HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) {
        OnlCgformHead onlCgformHead = null;
        long currentTimeMillis = System.currentTimeMillis();
        Result result = new Result<>();
        String str2 = "";
        String parameter = httpServletRequest.getParameter(CgformUtil.f279ay);
        StringBuffer stringBuffer = new StringBuffer();
        try {
            onlCgformHead = (OnlCgformHead) this.onlCgformHeadService.getById(str);
        } catch (Exception e) {
            result.setSuccess(false);
            result.setMessage(e.getMessage());
            f144a.error(e.getMessage(), e);
        }
        if (onlCgformHead == null) {
            return Result.error("数据库不存在该表记录");
        }
        LambdaQueryWrapper<OnlCgformField> lambdaQueryWrapper = new LambdaQueryWrapper();
        lambdaQueryWrapper.eq(OnlCgformField::getCgformHeadId, str);
        List<OnlCgformField> list = this.onlCgformFieldService.list(lambdaQueryWrapper);
        String parameter2 = httpServletRequest.getParameter(CgformUtil.f278ax);
        List<String> m318e = CgformUtil.m318e(list);
        if (oConvertUtils.isEmpty(parameter2) && onlCgformHead.getTableType().intValue() == 2 && oConvertUtils.isNotEmpty(onlCgformHead.getSubTableStr())) {
            for (String str3 : onlCgformHead.getSubTableStr().split(CgformUtil.f233E)) {
                OnlCgformHead onlCgformHead2 = this.onlCgformHeadService.getOne(new LambdaQueryWrapper<OnlCgformHead>().eq(OnlCgformHead::getTableName, str3));
                if (onlCgformHead2 != null) {
                    List<String> m328c = CgformUtil.m328c(this.onlCgformFieldService.list(new LambdaQueryWrapper<OnlCgformField>().eq(OnlCgformField::getCgformHeadId, onlCgformHead2.getId())), onlCgformHead2.getTableTxt());
                    if (m328c.size() > 0) {
                        m318e.addAll(m328c);
                    }
                }
            }
        }
        String parameter3 = httpServletRequest.getParameter(CgformUtil.f281aA);
        JSONObject parseObject = oConvertUtils.isNotEmpty(parameter3) ? JSONObject.parseObject(parameter3) : null;
        Map<String, MultipartFile> fileMap = ((MultipartHttpServletRequest) httpServletRequest).getFileMap();
        DataSource dataSource = (DataSource) SpringContextUtils.getApplicationContext().getBean(DataSource.class);
        String m33a = "";
		try {
			m33a = DbTableUtil.m33a(dataSource);
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (DBException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
        for (Map.Entry entry : fileMap.entrySet()) {
            MultipartFile multipartFile = (MultipartFile) entry.getValue();
            ImportParams importParams = new ImportParams();
            importParams.setDataHanlder(new CgFormExcelHandler(list, this.upLoadPath, this.uploadType));
            InputStream inputStream = null;
			try {
				inputStream = multipartFile.getInputStream();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
            try {
                List<Map> importExcel = ExcelImportUtil.importExcel(inputStream, Map.class, importParams);
                if (importExcel == null) {
                    str2 = "识别模版数据错误";
                    f144a.error(str2);
                } else {
                    if (CgformConstant.f368c.equals(onlCgformHead.getTableType()) && onlCgformHead.getRelationType().intValue() == 1) {
                        if (importExcel.size() > 1) {
                            Result<?> error = Result.error("一对一的表只能导入一条数据!");
                            if (inputStream != null) {
                                IOUtils.closeQuietly(inputStream);
                            }
                            return error;
                        }
                        Integer queryCountBySql = this.onlCgformFieldService.queryCountBySql(CgformUtil.m317f(onlCgformHead.getTableName()), null, null);
                        if (null != queryCountBySql && queryCountBySql.intValue() > 1) {
                            throw new TuringBootException("一对一的表只能导入一条数据!");
                        }
                    }
                    Object obj = "";
                    ArrayList arrayList = new ArrayList();
                    for (Map map : importExcel) {
                        boolean z = false;
                        Set<String> keySet = map.keySet();
                        HashMap hashMap = new HashMap(5);
                        for (String str4 : keySet) {
                            if (str4.indexOf("$subTable$") == -1) {
                                if (str4.indexOf("$mainTable$") != -1 && oConvertUtils.isNotEmpty(map.get(str4).toString())) {
                                    z = true;
                                    obj = m488a(onlCgformHead, dataSource, m33a);
                                }
                                hashMap.put(str4.replace("$mainTable$", ""), map.get(str4));
                            }
                        }
                        if ("Y".equals(onlCgformHead.getIsTree())) {
                            if (oConvertUtils.isEmpty(hashMap.get(onlCgformHead.getTreeParentIdField()))) {
                                hashMap.put(onlCgformHead.getTreeParentIdField(), CgformUtil.f304aX);
                            }
                            if (oConvertUtils.isEmpty(hashMap.get(onlCgformHead.getTreeIdField()))) {
                                hashMap.put(onlCgformHead.getTreeIdField(), CgformUtil.f304aX);
                            }
                        }
                        if (z) {
                            hashMap.put("id", obj);
                            arrayList.add(hashMap);
                            obj = hashMap.get("id");
                        }
                        if (parseObject != null) {
                            for (String str5 : parseObject.keySet()) {
                                System.out.println(str5 + CgformUtil.f215m + parseObject.getString(str5));
                                hashMap.put(str5, parseObject.getString(str5));
                            }
                        }
                        map.put("$mainTable$id", obj);
                    }
                    if (arrayList == null || arrayList.size() == 0) {
                        result.setSuccess(false);
                        result.setMessage("导入失败，匹配的数据条数为零!");
                        if (inputStream != null) {
                            IOUtils.closeQuietly(inputStream);
                        }
                        return result;
                    }
                    if ("1".equals(parameter)) {
                        Map<String, String> saveOnlineImportDataWithValidate = this.onlCgformSqlService.saveOnlineImportDataWithValidate(onlCgformHead, list, arrayList);
                        String str6 = saveOnlineImportDataWithValidate.get(OnlineImportValidator.f343a);
                        str2 = saveOnlineImportDataWithValidate.get(OnlineImportValidator.f344b);
                        if (str6 != null && str6.length() > 0) {
                            stringBuffer.append(onlCgformHead.getTableTxt() + "导入校验," + str2 + ",详情如下:\r\n" + str6);
                        }
                    } else {
                        this.onlCgformSqlService.saveBatchOnlineTable(onlCgformHead, list, arrayList);
                    }
                    if (oConvertUtils.isEmpty(parameter2) && onlCgformHead.getTableType().intValue() == 2 && oConvertUtils.isNotEmpty(onlCgformHead.getSubTableStr())) {
                        for (String str7 : onlCgformHead.getSubTableStr().split(CgformUtil.f233E)) {
                            OnlCgformHead onlCgformHead3 = this.onlCgformHeadService.getOne(new LambdaQueryWrapper<OnlCgformHead>().eq(OnlCgformHead::getTableName, str7));
                            if (onlCgformHead3 != null) {
                            	LambdaQueryWrapper<OnlCgformField> lambdaQueryWrapper2 = new LambdaQueryWrapper();
                                lambdaQueryWrapper2.eq(OnlCgformField::getCgformHeadId, onlCgformHead3.getId());
                                List<OnlCgformField> list2 = this.onlCgformFieldService.list(lambdaQueryWrapper2);
                                ArrayList arrayList2 = new ArrayList();
                                String tableTxt = onlCgformHead3.getTableTxt();
                                for (Map map2 : importExcel) {
                                    boolean z2 = false;
                                    HashMap hashMap2 = new HashMap();
                                    for (OnlCgformField onlCgformField : list2) {
                                        String mainTable = onlCgformField.getMainTable();
                                        String mainField = onlCgformField.getMainField();
                                        boolean z3 = onlCgformHead.getTableName().equals(mainTable) && oConvertUtils.isNotEmpty(mainField);
                                        String str8 = tableTxt + "_" + onlCgformField.getDbFieldTxt();
                                        if (z3) {
                                            hashMap2.put(onlCgformField.getDbFieldName(), map2.get("$mainTable$" + mainField));
                                        }
                                        Object obj2 = map2.get("$subTable$" + str8);
                                        if (null != obj2 && oConvertUtils.isNotEmpty(obj2.toString())) {
                                            z2 = true;
                                            hashMap2.put(onlCgformField.getDbFieldName(), obj2);
                                        }
                                    }
                                    if (z2) {
                                        hashMap2.put("id", m488a(onlCgformHead3, dataSource, m33a));
                                        arrayList2.add(hashMap2);
                                    }
                                }
                                if (arrayList2.size() > 0) {
                                    if ("1".equals(parameter)) {
                                        Map<String, String> saveOnlineImportDataWithValidate2 = this.onlCgformSqlService.saveOnlineImportDataWithValidate(onlCgformHead3, list2, arrayList2);
                                        String str9 = saveOnlineImportDataWithValidate2.get(OnlineImportValidator.f343a);
                                        String str10 = saveOnlineImportDataWithValidate2.get(OnlineImportValidator.f344b);
                                        if (str9 != null && str9.length() > 0) {
                                            stringBuffer.append(onlCgformHead3.getTableTxt() + "导入校验," + str10 + ",详情如下:\r\n" + str9);
                                        }
                                    } else {
                                        this.onlCgformSqlService.saveBatchOnlineTable(onlCgformHead3, list2, arrayList2);
                                    }
                                }
                            }
                        }
                    }
                }
                if (inputStream != null) {
                    IOUtils.closeQuietly(inputStream);
                }
            } catch (Exception e2) {
                result.setSuccess(false);
                result.setMessage("导入失败，" + e2.getMessage());
                if (inputStream != null) {
                    IOUtils.closeQuietly(inputStream);
                }
                return result;
            }
        }
        result.setSuccess(true);
        if (!"1".equals(parameter) || stringBuffer.length() <= 0) {
            result.setMessage("导入成功!");
        } else {
            result.setResult(CgformUtil.m374a(this.upLoadPath, onlCgformHead.getTableTxt(), stringBuffer));
            result.setMessage(str2);
            result.setCode(201);
        }
        f144a.info("=====online导入数据完成,耗时:" + (System.currentTimeMillis() - currentTimeMillis) + "毫秒=====");
        return result;
    }

    @PostMapping({"/doButton"})
    /* renamed from: a */
    public Result<?> m503a(@RequestBody JSONObject jSONObject) {
        String string = jSONObject.getString("formId");
        String string2 = jSONObject.getString("dataId");
        String string3 = jSONObject.getString("buttonCode");
        jSONObject.getJSONObject("uiFormData");
        try {
            this.onlCgformHeadService.executeCustomerButton(string3, string, string2);
            return Result.ok("执行成功!");
        } catch (Exception e) {
            f144a.error(e.getMessage(), e);
            return Result.error("执行失败," + e.getMessage());
        }
    }

    /* renamed from: a */
    public Object m488a(OnlCgformHead onlCgformHead, DataSource dataSource, String str) throws SQLException, DBException {
        Object obj = null;
        String idType = onlCgformHead.getIdType();
        String idSequence = onlCgformHead.getIdSequence();
        if (oConvertUtils.isNotEmpty(idType) && "UUID".equalsIgnoreCase(idType)) {
            obj = CgformUtil.m385a();
        } else if (oConvertUtils.isNotEmpty(idType) && "NATIVE".equalsIgnoreCase(idType)) {
            if (oConvertUtils.isNotEmpty(str) && "oracle".equalsIgnoreCase(str)) {
                try {
                    obj = Long.valueOf(new OracleSequenceMaxValueIncrementer(dataSource, "HIBERNATE_SEQUENCE").nextLongValue());
                } catch (Exception e) {
                    f144a.error(e.getMessage(), e);
                }
            } else if (oConvertUtils.isNotEmpty(str) && "postgres".equalsIgnoreCase(str)) {
                try {
                    obj = Long.valueOf(new PostgreSQLSequenceMaxValueIncrementer(dataSource, "HIBERNATE_SEQUENCE").nextLongValue());
                } catch (Exception e2) {
                    f144a.error(e2.getMessage(), e2);
                }
            } else {
                obj = null;
            }
        } else if (oConvertUtils.isNotEmpty(idType) && "SEQUENCE".equalsIgnoreCase(idType)) {
            if (oConvertUtils.isNotEmpty(str) && "oracle".equalsIgnoreCase(str)) {
                try {
                    obj = Long.valueOf(new OracleSequenceMaxValueIncrementer(dataSource, idSequence).nextLongValue());
                } catch (Exception e3) {
                    f144a.error(e3.getMessage(), e3);
                }
            } else if (oConvertUtils.isNotEmpty(str) && "postgres".equalsIgnoreCase(str)) {
                try {
                    obj = Long.valueOf(new PostgreSQLSequenceMaxValueIncrementer(dataSource, idSequence).nextLongValue());
                } catch (Exception e4) {
                    f144a.error(e4.getMessage(), e4);
                }
            } else {
                obj = null;
            }
        } else {
            obj = CgformUtil.m385a();
        }
        return obj;
    }

    /* renamed from: a */
    private void m491a(Map map, List<OnlCgformField> list) {
        List<DictModel> queryTableDictItemsByCode;
        for (OnlCgformField onlCgformField : list) {
            String dictTable = onlCgformField.getDictTable();
            String dictField = onlCgformField.getDictField();
            String dictText = onlCgformField.getDictText();
            if (!oConvertUtils.isEmpty(dictTable) || !oConvertUtils.isEmpty(dictField)) {
                if (!CgformUtil.f241M.equals(onlCgformField.getFieldShowType())) {
                    String valueOf = String.valueOf(map.get(onlCgformField.getDbFieldName()));
                    if (oConvertUtils.isEmpty(dictTable)) {
                        queryTableDictItemsByCode = this.sysBaseAPI.queryDictItemsByCode(dictField);
                    } else {
                        queryTableDictItemsByCode = this.sysBaseAPI.queryTableDictItemsByCode(dictTable, dictText, dictField);
                    }
                    for (DictModel dictModel : queryTableDictItemsByCode) {
                        if (valueOf.equals(dictModel.getText())) {
                            map.put(onlCgformField.getDbFieldName(), dictModel.getValue());
                        }
                    }
                }
            }
        }
    }

    @GetMapping({"/checkOnlyTable"})
    /* renamed from: j */
    public Result<?> m463j(@RequestParam("tbname") String str, @RequestParam("id") String str2) {
        if (oConvertUtils.isEmpty(str2)) {
            if (DbTableUtil.m38a(str).booleanValue()) {
                return Result.ok(-1);
            }
            if (oConvertUtils.isNotEmpty((OnlCgformHead) this.onlCgformHeadService.getOne(new LambdaQueryWrapper<OnlCgformHead>().eq(OnlCgformHead::getTableName, str)))) {
                return Result.ok(-1);
            }
        } else if (!str.equals((this.onlCgformHeadService.getById(str2)).getTableName()) && DbTableUtil.m38a(str).booleanValue()) {
            return Result.ok(-1);
        }
        return Result.ok(1);
    }

    @PostMapping({"/codeGenerate"})
    @RequiresPermissions({"online:form:generateCode"})
    /* renamed from: b */
    public Result<?> m486b(@RequestBody JSONObject jSONObject) {
        List<String> generateOneToMany;
        OnlGenerateModel onlGenerateModel = (OnlGenerateModel) JSONObject.parseObject(jSONObject.toJSONString(), OnlGenerateModel.class);
        if ((this.jeecgBaseConfig.getFirewall() != null ? this.jeecgBaseConfig.getFirewall().getDataSourceSafe().booleanValue() : false) && !DbReadTableUtil.getProjectPath().equals(onlGenerateModel.getProjectPath())) {
            onlGenerateModel.setProjectPath(DbReadTableUtil.getProjectPath());
            f144a.warn("数据源安全模式下，自定义代码生成路径无效，使用全局配置的路径 ::{}", DbReadTableUtil.getProjectPath());
        }
        try {
            if ("1".equals(onlGenerateModel.getJformType())) {
                generateOneToMany = this.onlCgformHeadService.generateCode(onlGenerateModel);
            } else {
                generateOneToMany = this.onlCgformHeadService.generateOneToMany(onlGenerateModel);
            }
            String str = ((LoginUser) SecurityUtils.getSubject().getPrincipal()).getUsername() + onlGenerateModel.getTableName() + oConvertUtils.randomGen(16);
            Result<?> ok = Result.ok(generateOneToMany);
            this.redisUtil.set(str, onlGenerateModel.getProjectPath().replaceAll("\\\\", "/"), 1800L);
            ok.setMessage(str);
            return ok;
        } catch (Exception e) {
            e.printStackTrace();
            return Result.error(e.getMessage());
        }
    }

    @GetMapping({"/codeView"})
    /* renamed from: a */
    public void m496a(@RequestParam(name = "path") String str, @RequestParam(name = "pathKey") String str2, HttpServletResponse httpServletResponse) {
        String str3 = "";
        try {
            str3 = URLDecoder.decode(str, "UTF-8");
            if (str3.indexOf("src/main/java") == -1 && str3.indexOf("src%5Cmain%5Cjava") == -1 && str3.indexOf("src\\main\\java") == -1) {
                f144a.error("代码不在`src/main/java`目录中，不允许预览");
                JwtUtil.responseError(httpServletResponse, 200, "代码不在`src/main/java`目录中，不允许预览");
                return;
            }
        } catch (UnsupportedEncodingException e) {
            f144a.error(" path 不合法！！！", e.getMessage());
        }
        Object obj = this.redisUtil.get(str2);
        if (obj == null) {
            f144a.error("路径失效，请重新操作!");
            JwtUtil.responseError(httpServletResponse, 500, "路径失效，请重新操作!");
            return;
        }
        if (str3.replaceAll("\\\\", "/").indexOf(obj.toString()) < 0) {
            f144a.error("非法的请求路径，请重新操作!");
            JwtUtil.responseError(httpServletResponse, 500, "非法的请求路径，请重新操作!");
            return;
        }
        String substring = str3.substring(str3.lastIndexOf("/") + 1);
        File file = new File(str3);
        if (file.exists()) {
            httpServletResponse.setContentType("application/force-download");
            httpServletResponse.addHeader("Content-Disposition", "attachment;fileName=" + substring);
            byte[] bArr = new byte[1024];
            FileInputStream fileInputStream = null;
            BufferedInputStream bufferedInputStream = null;
            try {
                try {
                    fileInputStream = new FileInputStream(file);
                    bufferedInputStream = new BufferedInputStream(fileInputStream);
                    ServletOutputStream outputStream = httpServletResponse.getOutputStream();
                    for (int read = bufferedInputStream.read(bArr); read != -1; read = bufferedInputStream.read(bArr)) {
                        outputStream.write(bArr, 0, read);
                    }
                    if (bufferedInputStream != null) {
                        try {
                            bufferedInputStream.close();
                        } catch (IOException e2) {
                            e2.printStackTrace();
                        }
                    }
                    if (fileInputStream != null) {
                        try {
                            fileInputStream.close();
                        } catch (IOException e3) {
                            e3.printStackTrace();
                        }
                    }
                } catch (Exception e4) {
                    e4.printStackTrace();
                    if (bufferedInputStream != null) {
                        try {
                            bufferedInputStream.close();
                        } catch (IOException e5) {
                            e5.printStackTrace();
                        }
                    }
                    if (fileInputStream != null) {
                        try {
                            fileInputStream.close();
                        } catch (IOException e6) {
                            e6.printStackTrace();
                        }
                    }
                }
            } catch (Throwable th) {
                if (bufferedInputStream != null) {
                    try {
                        bufferedInputStream.close();
                    } catch (IOException e7) {
                        e7.printStackTrace();
                    }
                }
                if (fileInputStream != null) {
                    try {
                        fileInputStream.close();
                    } catch (IOException e8) {
                        e8.printStackTrace();
                    }
                }
                throw th;
            }
        }
    }

    /* JADX WARN: Type inference failed for: r0v60, types: [org.jeecg.modules.online.cgform.c.a$1] */
    /* JADX WARN: Type inference failed for: r0v70, types: [org.jeecg.modules.online.cgform.c.a$1] */
    /* JADX WARN: Type inference failed for: r0v85, types: [org.jeecg.modules.online.cgform.c.a$1] */
    @PostMapping({"/downGenerateCode"})
    @RequiresPermissions({"online:form:generateCode"})
    /* renamed from: a */
    public void m502a(@RequestBody JSONObject jSONObject, HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) {
        String string = jSONObject.getString("fileList");
        String string2 = jSONObject.getString("pathKey");
        try {
            string = URLDecoder.decode(string, "UTF-8");
        } catch (UnsupportedEncodingException e) {
            f144a.error(" fileList 不合法！！！", e.getMessage());
        }
        ArrayList<String> arrayList = new ArrayList();
        for (String str : string.split(CgformUtil.f233E)) {
            arrayList.add(str);
        }
        List list = (List) arrayList.stream().filter(str2 -> {
            return str2.indexOf("src/main/java") == -1 && str2.indexOf("src%5Cmain%5Cjava") == -1 && str2.indexOf("src\\main\\java") == -1;
        }).collect(Collectors.toList());
        if (arrayList == null || (list != null && list.size() > 0)) {
            f144a.error(" fileList 不合法！！！", arrayList);
            return;
        }
        Object obj = this.redisUtil.get(string2);
        if (obj == null) {
            f144a.error("路径失效，请重新操作!");
            JwtUtil.responseError(httpServletResponse, 500, "路径失效，请重新操作!");
            return;
        }
        String obj2 = obj.toString();
        for (String str3 : arrayList) {
            if (str3.replaceAll("\\\\", "/").indexOf(obj2) < 0) {
                f144a.error("非法的请求路径，请重新操作!");
                JwtUtil.responseError(httpServletResponse, 500, "非法的请求路径，请重新操作!");
                return;
            }
        }
        String str4 = "生成代码_" + System.currentTimeMillis() + ".zip";
        try {
            str4 = URLEncoder.encode(str4, "UTF-8");
        } catch (UnsupportedEncodingException e2) {
        }
        String str5 = "/opt/temp/codegenerate/";
        String property = System.getProperty("os.name");
        if (null != property && property.startsWith("Mac OS")) {
            str5 = "~/temp/codegenerate/";
        }
        final String str6 = str5 + str4;
        File m287a = GenerateCodeFileToZip.m287a(arrayList, str6);
        if (m287a.exists()) {
            httpServletResponse.setContentType("application/force-download");
            httpServletResponse.addHeader("Content-Disposition", "attachment;fileName=" + str4);
            byte[] bArr = new byte[1024];
            FileInputStream fileInputStream = null;
            BufferedInputStream bufferedInputStream = null;
            try {
                try {
                    fileInputStream = new FileInputStream(m287a);
                    bufferedInputStream = new BufferedInputStream(fileInputStream);
                    ServletOutputStream outputStream = httpServletResponse.getOutputStream();
                    for (int read = bufferedInputStream.read(bArr); read != -1; read = bufferedInputStream.read(bArr)) {
                        outputStream.write(bArr, 0, read);
                    }
                    if (bufferedInputStream != null) {
                        try {
                            bufferedInputStream.close();
                        } catch (IOException e3) {
                            e3.printStackTrace();
                        }
                    }
                    if (fileInputStream != null) {
                        try {
                            fileInputStream.close();
                        } catch (IOException e4) {
                            e4.printStackTrace();
                        }
                    }
                    new Thread() { // from class: org.jeecg.modules.online.cgform.c.a.1
                        @Override // java.lang.Thread, java.lang.Runnable
                        public void run() {
                            try {
                                Thread.sleep(10000L);
                                FileUtil.del(str6);
                            } catch (InterruptedException e5) {
                                e5.printStackTrace();
                            }
                        }
                    }.start();
                } catch (Throwable th) {
                    if (bufferedInputStream != null) {
                        try {
                            bufferedInputStream.close();
                        } catch (IOException e5) {
                            e5.printStackTrace();
                        }
                    }
                    if (fileInputStream != null) {
                        try {
                            fileInputStream.close();
                        } catch (IOException e6) {
                            e6.printStackTrace();
                        }
                    }
                    new Thread() { // from class: org.jeecg.modules.online.cgform.c.a.1
                        @Override // java.lang.Thread, java.lang.Runnable
                        public void run() {
                            try {
                                Thread.sleep(10000L);
                                FileUtil.del(str6);
                            } catch (InterruptedException e52) {
                                e52.printStackTrace();
                            }
                        }
                    }.start();
                    throw th;
                }
            } catch (Exception e7) {
                e7.printStackTrace();
                if (bufferedInputStream != null) {
                    try {
                        bufferedInputStream.close();
                    } catch (IOException e8) {
                        e8.printStackTrace();
                    }
                }
                if (fileInputStream != null) {
                    try {
                        fileInputStream.close();
                    } catch (IOException e9) {
                        e9.printStackTrace();
                    }
                }
                new Thread() { // from class: org.jeecg.modules.online.cgform.c.a.1
                    @Override // java.lang.Thread, java.lang.Runnable
                    public void run() {
                        try {
                            Thread.sleep(10000L);
                            FileUtil.del(str6);
                        } catch (InterruptedException e52) {
                            e52.printStackTrace();
                        }
                    }
                }.start();
            }
        }
    }

    @GetMapping({"/getTreeData/{code}"})
    public Result<Map<String, Object>> m469e(@PathVariable("code") String str, HttpServletRequest httpServletRequest) {
        Result<Map<String, Object>> result = new Result<>();
        OnlCgformHead onlCgformHead = (OnlCgformHead) this.onlCgformHeadService.getById(str);
        if (onlCgformHead == null) {
            result.error500("实体不存在");
            return result;
        }
        try {
            String tableName = onlCgformHead.getTableName();
            String treeIdField = onlCgformHead.getTreeIdField();
            String treeParentIdField = onlCgformHead.getTreeParentIdField();
            ArrayList newArrayList = Lists.newArrayList(new String[]{treeIdField, treeParentIdField});
            Map<String, Object> m358a = CgformUtil.m358a(httpServletRequest);
            if (m358a.get(treeIdField) != null) {
                m358a.get(treeIdField).toString();
            }
            if (m358a.get("hasQuery") != null && "false".equals(m358a.get("hasQuery")) && m358a.get(treeParentIdField) == null) {
                m358a.put(treeParentIdField, CgformUtil.f304aX);
            } else {
                m358a.put("pageSize", -521);
                m358a.put(treeParentIdField, m358a.get(treeParentIdField));
            }
            m358a.put(treeIdField, null);
            Map<String, Object> queryAutoTreeNoPage = this.onlCgformFieldService.queryAutoTreeNoPage(tableName, str, m358a, newArrayList, treeParentIdField);
            m489a(onlCgformHead, queryAutoTreeNoPage);
            result.setResult(queryAutoTreeNoPage);
        } catch (Exception e) {
            f144a.error(e.getMessage(), e);
            result.error500("数据库查询失败" + e.getMessage());
        }
        result.setOnlTable(onlCgformHead.getTableName());
        return result;
    }

    /* renamed from: a */
    private void m489a(OnlCgformHead onlCgformHead, Map<String, Object> map) throws BusinessException {
        this.onlCgformHeadService.executeEnhanceList(onlCgformHead, "query", (List) map.get("records"));
    }

    @PostMapping({"/crazyForm/{name}"})
    /* renamed from: b */
    public Result<?> m484b(@PathVariable("name") String str, @RequestBody JSONObject jSONObject) {
        Result result = new Result<>();
        try {
            String m385a = CgformUtil.m385a();
            jSONObject.put("id", m385a);
            this.onlCgformHeadService.addCrazyFormData(str, jSONObject);
            result.setResult(m385a);
            result.setMessage("保存成功");
            return result;
        } catch (Exception e) {
            f144a.error("OnlCgformApiController.formAddForDesigner()发生异常：" + e.getMessage(), e);
            return Result.error("保存失败");
        }
    }

    @PutMapping({"/crazyForm/{name}"})
    /* renamed from: c */
    public Result<?> m478c(@PathVariable("name") String str, @RequestBody JSONObject jSONObject) {
        try {
            jSONObject.remove("create_by");
            jSONObject.remove("create_time");
            jSONObject.remove("update_by");
            jSONObject.remove("update_time");
            this.onlCgformHeadService.editCrazyFormData(str, jSONObject);
            return Result.ok("保存成功!");
        } catch (Exception e) {
            f144a.error("OnlCgformApiController.formEditForDesigner()发生异常：" + e.getMessage(), e);
            return Result.error("保存失败");
        }
    }

    @AutoLog(operateType = 1, value = "online列表加载", module = ModuleType.ONLINE)
    @GetMapping({"/getErpColumns/{code}"})
    /* renamed from: d */
    public Result<Map<String, Object>> m474d(@PathVariable("code") String str) {
        Result<Map<String, Object>> result = new Result<>();
        OnlCgformHead onlCgformHead = (OnlCgformHead) this.onlCgformHeadService.getById(str);
        if (onlCgformHead == null) {
            result.error500("实体不存在");
            return result;
        }
        HashMap hashMap = new HashMap(5);
        LoginUser loginUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
        hashMap.put(CgReportConstant.f469a, this.onlineService.queryOnlineConfig(onlCgformHead, loginUser.getUsername()));
        if (CgformUtil.f275au.equals(onlCgformHead.getThemeTemplate()) && onlCgformHead.getTableType().intValue() == 2) {
            String subTableStr = onlCgformHead.getSubTableStr();
            if (oConvertUtils.isNotEmpty(subTableStr)) {
                ArrayList arrayList = new ArrayList();
                for (String str2 : subTableStr.split(CgformUtil.f233E)) {
                    OnlCgformHead onlCgformHead2 = this.onlCgformHeadService.getOne(new LambdaQueryWrapper<OnlCgformHead>().eq(OnlCgformHead::getTableName, str2));
                    if (onlCgformHead2 != null) {
                        arrayList.add(this.onlineService.queryOnlineConfig(onlCgformHead2, loginUser.getUsername()));
                    }
                }
                if (arrayList.size() > 0) {
                    hashMap.put("subList", arrayList);
                }
            }
        }
        result.setOnlTable(onlCgformHead.getTableName());
        result.setResult(hashMap);
        result.setSuccess(true);
        return result;
    }

    @AutoLog(operateType = 1, value = "online表单加载", module = ModuleType.ONLINE)
    @GetMapping({"/getErpFormItem/{code}"})
    /* renamed from: f */
    public Result<?> m467f(@PathVariable("code") String str, HttpServletRequest httpServletRequest) {
        OnlCgformHead onlCgformHead = (OnlCgformHead) this.onlCgformHeadService.getById(str);
        if (onlCgformHead == null) {
            Result.error("表不存在");
        }
        Result result = new Result<>();
        result.setResult(CgformUtil.m345b(this.onlineService.queryOnlineFormObj(onlCgformHead, ((LoginUser) SecurityUtils.getSubject().getPrincipal()).getUsername())));
        result.setOnlTable(onlCgformHead.getTableName());
        return result;
    }

    @GetMapping({"/querySelectOptions"})
    /* renamed from: a */
    public Result<List<TreeModel>> m490a(@ModelAttribute LinkDown linkDown) {
        Result<List<TreeModel>> result = new Result<>();
        try {
            result.setResult(this.onlCgformFieldService.queryDataListByLinkDown(linkDown));
            result.setSuccess(true);
        } catch (Exception e) {
            f144a.warn("online级联下拉数据加载失败：{}", e.getMessage());
            e.printStackTrace();
            result.setSuccess(false);
        }
        return result;
    }

    @GetMapping({"/data/{tableName}/queryById"})
    /* renamed from: a */
    public JSONObject m498a(@PathVariable("tableName") String str, @RequestParam(name = "mock", required = false) Boolean bool, HttpServletRequest httpServletRequest) {
    	LambdaQueryWrapper<OnlCgformHead> lambdaQueryWrapper = new LambdaQueryWrapper();
        lambdaQueryWrapper.eq(OnlCgformHead::getTableName, str);
        OnlCgformHead onlCgformHead = this.onlCgformHeadService.getOne(lambdaQueryWrapper);
        if (onlCgformHead == null) {
            throw new TuringBootException("Online表单 " + str + " 不存在");
        }
        try {
            Map<String, Object> m358a = CgformUtil.m358a(httpServletRequest);
            ArrayList arrayList = new ArrayList();
            arrayList.add("id");
            Map<String, Object> queryAutolistPage = this.onlCgformFieldService.queryAutolistPage(onlCgformHead, m358a, arrayList);
            m489a(onlCgformHead, queryAutolistPage);
            List m380a = CgformUtil.m380a(queryAutolistPage.get("records"), Object.class);
            if (Boolean.TRUE.equals(bool) && (m380a == null || m380a.size() == 0)) {
                Map<String, Object> generateMockData = this.onlCgformFieldService.generateMockData(onlCgformHead.getTableName());
                ArrayList arrayList2 = new ArrayList();
                arrayList2.add(generateMockData);
                queryAutolistPage.put("records", arrayList2);
            }
            JSONObject jSONObject = new JSONObject();
            jSONObject.put("data", queryAutolistPage.get("records"));
            return jSONObject;
        } catch (Exception e) {
            f144a.error(e.getMessage(), e);
            throw new TuringBootException("数据库查询失败，" + e.getMessage());
        }
    }
}
